package com.zhb.cloud.template;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

public class TableAndColumnUtil {

	public static List<String> getTables() throws Exception {
		List<String> tableList = new ArrayList<String>();
		DatabaseMetaData metaData = MetaDataUtil.getMetaDatabaseMetaData();
		ResultSet resultSet = metaData.getTables(null, "%", "%", new String[] { "TABLE" });
		while (resultSet.next()) {
			String tableName = resultSet.getString("TABLE_NAME");
			tableList.add(tableName);
		}
		return tableList;
	}

	public static List<String> getColumnByTable(String table) throws Exception {
		List<String> columnList = new ArrayList<String>();
		DatabaseMetaData metaData = MetaDataUtil.getMetaDatabaseMetaData();
		ResultSet resultSet = metaData.getColumns(null, null, table, null);
		while (resultSet.next()) {
			String column = CamleNameUtil.columnNameWithoutProfix(resultSet.getString("column_name"));
			columnList.add(column);
		}
		return columnList;
	}
}
